﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NhanAi.DAO;
using NhanAi.Entity;
using Home.Utils;
namespace NhanAi.Admin
{
    public partial class ListUsers :ListPage
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            Authenticate();
            UserDao dao = new UserDao();
            string searchString = Request["searchString"];
            pageNum = TypeWrapper.GetInt32(Request["page"]);
            if (pageNum == 0) pageNum = 1;
            int total = 0;
            if (Request.HttpMethod == "POST")
            {
                string ids = Request["ids"];
                if (!String.IsNullOrEmpty(ids))
                {
                    dao.Delete(ids);
                    SetMessage("Xóa thành công", "");
                }
            }
            List<User> list;
            total = 0;
            if (!String.IsNullOrEmpty(searchString))
            {
                 list = dao.ReadMany(PAGE_SIZE, pageNum, "%" + searchString + "%", "%" + searchString + "%", null, -1, -1,out total );
            }
            else
            {
                list = dao.ReadMany(PAGE_SIZE, pageNum, null, null, null, -1, -1,out total );
            }
            rptData.DataSource = list;
            rptData.DataBind();
            paging.TotalItemCount = total;
            paging.PageNumber = pageNum;
            paging.PageSize = PAGE_SIZE;
            paging.SearchString = searchString;
            SetCurrentPage("User");
        }
    }
}